package 贪心算法.分发饼干;

import java.util.Arrays;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/1/31 13:39
 * @description:
 * @version:
 */
public class Solution {
    public static void main(String[] args) {
        int[] arrG = {1,7,8,9};
        int[] arrS = {2,3,4};
        System.out.println(findContentChildren(arrG, arrS));
    }


    public static int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int m = g.length, n = s.length;
        int count = 0;
        for (int i = 0, j = 0; i < m && j < n; i++, j++) {
            while (j < n && g[i] > s[j]) {
                j++;
            }
            if (j < n) {
                count++;
            }
        }
        return count;
    }
}
